package com.qingzhuge.pay.service.impl;

import com.qingzhuge.pay.EnumPayType;
import com.qingzhuge.pay.dao.SysPayPropertiesDao;
import com.qingzhuge.pay.entity.SysPayProperty;
import com.qingzhuge.pay.service.ISysPayPropertiesService;
import com.qingzhuge.service.BasePkLongServiceImpl;
import org.springframework.stereotype.Service;

/**
 * @author : zero.xiao
 * @description :
 * @date : 2018/11/15 0015 下午 18:38
 * @modified :
 * @since :
 */
@Service
public class SysPayPropertiesServiceImpl extends BasePkLongServiceImpl<SysPayPropertiesDao, SysPayProperty>
        implements ISysPayPropertiesService {

    @Override
    public SysPayProperty findWx() {
        return baseDao.findByTypeAndEnableIsTrue(EnumPayType.weixin);
    }

    @Override
    public SysPayProperty findAlipay() {
        return baseDao.findByTypeAndEnableIsTrue(EnumPayType.alipay);
    }

    @Override
    public SysPayProperty findByIdAndTypeAndEnableIsFalse(Long id, EnumPayType type) {
        if (null == id || null == type){
            return null;
        }
        return baseDao.findByIdAndTypeAndEnableIsFalse(id,type);
    }

    @Override
    public void cert(Long id, byte[] file) {
        SysPayProperty payProperty = findById(id);
        if (null != payProperty) {
            payProperty.setKeyContent(file);
            save(payProperty);
            saveCache(payProperty);
        }
    }
}
